﻿// -----------------------------------------------------------------------
// <copyright file="StatusResult.cs" company="Zen Design Corp">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Zen.BlackBerry.Push
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using Zen.BlackBerry.Common;
	using Zen.BlackBerry.Pap;

	/// <summary>
	/// Represents the result of a status query including the response from the
	/// PPG and sets of subscriber ids that were not sent to the PPG because
	/// they were invalid in some way (i.e. they do not exist, are inactive, or
	/// are suspended at the time of the status query).
	/// </summary>
	public class StatusResult
	{
		private ISet<string> _doNotExistSubscriberIds = new HashSet<string>();
		private ISet<string> _inactiveSubscriberIds = new HashSet<string>();
		private ISet<string> _suspendedSubscriberIds = new HashSet<string>();
		private List<PushOutcome> _outcomes = new List<PushOutcome>();

		/// <summary>
		/// Initializes a new instance of the <see cref="StatusResult"/> class.
		/// </summary>
		/// <param name="pushId">The push id.</param>
		/// <param name="applicationId">The application id.</param>
		public StatusResult(string pushId, string applicationId)
		{
			PushId = pushId;
			ApplicationId = applicationId;
		}

		/// <summary>
		/// Gets the push id.
		/// </summary>
		/// <value>The push id.</value>
		public string PushId
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets the application id.
		/// </summary>
		/// <value>The application id.</value>
		public string ApplicationId
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets or sets the collection of subscribers that could not be found
		/// in storage.
		/// </summary>
		/// <value>The do not exist subscriber ids.</value>
		public ISet<string> DoNotExistSubscriberIds
		{
			get
			{
				if (_doNotExistSubscriberIds == null)
				{
					_doNotExistSubscriberIds = new HashSet<string>();
				}
				return _doNotExistSubscriberIds;
			}
			set
			{
				_doNotExistSubscriberIds = value;
			}
		}

		/// <summary>
		/// Gets or sets the subscriber ids that match inactive subscribers.
		/// </summary>
		/// <value>The inactive subscriber ids.</value>
		public ISet<string> InactiveSubscriberIds
		{
			get
			{
				if (_inactiveSubscriberIds == null)
				{
					_inactiveSubscriberIds = new HashSet<string>();
				}
				return _inactiveSubscriberIds;
			}
			set
			{
				_inactiveSubscriberIds = value;
			}
		}

		/// <summary>
		/// Gets or sets the subscriber ids that match suspended subscribers.
		/// </summary>
		/// <value>The suspended subscriber ids.</value>
		public ISet<string> SuspendedSubscriberIds
		{
			get
			{
				if (_suspendedSubscriberIds == null)
				{
					_suspendedSubscriberIds = new HashSet<string>();
				}
				return _suspendedSubscriberIds;
			}
			set
			{
				_suspendedSubscriberIds = value;
			}
		}

		/// <summary>
		/// Gets the outcomes.
		/// </summary>
		/// <value>The outcomes.</value>
		public IList<PushOutcome> Outcomes
		{
			get
			{
				return _outcomes;
			}
		}

		/// <summary>
		/// Adds the outcome.
		/// </summary>
		/// <param name="address">The address.</param>
		/// <param name="statusCode">The status code.</param>
		/// <param name="description">The description.</param>
		/// <param name="eventTime">The event time.</param>
		/// <param name="messageState">State of the message.</param>
		/// <param name="isApplicationReliable">if set to <c>true</c> [is application reliable].</param>
		public void AddOutcome(
			string address,
			StatusCode statusCode,
			string description,
			DateTime? eventTime,
			MessageState messageState,
			bool isApplicationReliable)
		{
			_outcomes.Add(new PushOutcome(
				address,
				statusCode,
				description,
				eventTime,
				messageState,
				isApplicationReliable));
		}
	}
}
